# ----------------------------------------------------------------------------
# prepare

cmake_minimum_required(VERSION 2.8.8)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
# ============================================================================


# ----------------------------------------------------------------------------
# customisation
set ( PROJECT_NAME libalc )

# ============================================================================


# ----------------------------------------------------------------------------
# configure the project

project( ${PROJECT_NAME} )
set(${PROJECT_NAME}_MAJOR_VERSION 1)
set(${PROJECT_NAME}_MINOR_VERSION 0)
set(${PROJECT_NAME}_PATCH_VERSION 0)
set(${PROJECT_NAME}_VERSION
  ${${PROJECT_NAME}_MAJOR_VERSION}.${${PROJECT_NAME}_MINOR_VERSION}.${${PROJECT_NAME}_PATCH_VERSION})

if (NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY  "${PROJECT_BINARY_DIR}/build/bin" )
endif(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)

if (NOT EXECUTABLE_OUTPUT_PATH)
set ( EXECUTABLE_OUTPUT_PATH  "${PROJECT_BINARY_DIR}/build/bin" )
endif(NOT EXECUTABLE_OUTPUT_PATH)

if (NOT LIBRARY_OUTPUT_PATH)
set ( LIBRARY_OUTPUT_PATH  "${PROJECT_BINARY_DIR}/build/lib" )
endif(NOT LIBRARY_OUTPUT_PATH)

if (NOT INCLUDE_OUTPUT_PATH)
set ( INCLUDE_OUTPUT_PATH  "${PROJECT_BINARY_DIR}/build/include/${PROJECT_NAME}" )
else(NOT INCLUDE_OUTPUT_PATH)
set ( INCLUDE_OUTPUT_PATH  "${INCLUDE_OUTPUT_PATH}/../${PROJECT_NAME}" )
endif(NOT INCLUDE_OUTPUT_PATH)

include_directories(
  "${PROJECT_SOURCE_DIR}"
  "${PROJECT_BINARY_DIR}/build/include"
)

INCLUDE (CheckTypeSize)
CHECK_TYPE_SIZE("short" TYPE_SHORT)
CHECK_TYPE_SIZE("int" TYPE_INT)
CHECK_TYPE_SIZE("long" TYPE_LONG)
CHECK_TYPE_SIZE("long long" TYPE_LONG_LONG)
CHECK_TYPE_SIZE("float" TYPE_FLOAT)
CHECK_TYPE_SIZE("double" TYPE_DOUBLE)
CHECK_TYPE_SIZE("long double" TYPE_LONG_DOUBLE)

INCLUDE (CheckFunctionExists)
CHECK_FUNCTION_EXISTS(strtoull HAVE_STRTOULL)
CHECK_FUNCTION_EXISTS(_strtoui64 HAVE_STRTOUI64)
CHECK_FUNCTION_EXISTS(strtoll HAVE_STRTOLL)
CHECK_FUNCTION_EXISTS(_strtoi64 HAVE_STRTOI64)


if (WIN32)
  # set stuff for windows
  add_definitions( -DLIBALC_WIN32=1 )
else (WIN32)
  # set stuff for other systems

endif (WIN32)

if   (CMAKE_BUILD_TYPE STREQUAL "Debug")
    add_definitions( -DLIBALC_DEBUG=1 )
    # enable debug logging by setting this to on
    set( DebugLogEnabled true )
    message("Building a debug build of libalc...")
else (CMAKE_BUILD_TYPE STREQUAL "Debug")
    add_definitions( -DLIBALC_NO_DEBUG=1 )
    # enable debug logging by setting this to on
    set( DebugLogEnabled false )
endif (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_DEBUG_POSTFIX  "_debug")

CONFIGURE_FILE(
    ${PROJECT_NAME}_config.h.in
    ${INCLUDE_OUTPUT_PATH}/${PROJECT_NAME}_config.h
)
CONFIGURE_FILE(
    ${PROJECT_NAME}_version.h.in
    ${INCLUDE_OUTPUT_PATH}/${PROJECT_NAME}_version.h
)

# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)

# ============================================================================


# ----------------------------------------------------------------------------
# external libraries


# ============================================================================


# ----------------------------------------------------------------------------
# modules
set(modules 
    "core"
    "sglib"
    "cfgpath"
    "inih"
)

# will accumulate the libraries (each module will add itself)
set ( modules_libs )

# testing files are accumulated in modules_testing_src
# generated libraries are accumulated in modules_libs
FOREACH (mod ${modules})
    add_subdirectory( ${mod} )
ENDFOREACH(mod)
# ============================================================================


# ----------------------------------------------------------------------------
# Create release
set ( LIB_SOURCES
    dummy.c
)
set ( LIB_HEADERS
    "libalc_global.h"
)

add_library( ${PROJECT_NAME} SHARED
    ${LIB_SOURCES}
)
target_link_libraries( ${PROJECT_NAME}
    "alc-core"
    "cfgpath"
    "inih"
)

if (INCLUDE_OUTPUT_PATH)
    FOREACH (hfile ${LIB_HEADERS})
        execute_process(
            COMMAND ${CMAKE_COMMAND} -E copy_if_different "${hfile}" "${INCLUDE_OUTPUT_PATH}/${hfile}"
            WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
        )
    ENDFOREACH(hfile)
endif (INCLUDE_OUTPUT_PATH)

# ============================================================================





